<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Http\Request;

class InvalidRequestException extends Exception
{

    public function __construct(int $code = 0)
    {
        $this->code = $code;
        parent::__construct($code);
    }

    public function render(Request $request)
    {
        $message = get_errormsg_code($this->code);

        if ($request->expectsJson()) {
            return response()->json(['msg' => $message], $this->code);
        }

        return response()->json([
            'code' => $this->code,
            'msg' => $message,
            'data' => []
        ], 200, ['charset' => 'utf-8']);
    }

}
